#include <iostream>
#include <iomanip>
#include <map>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
typedef std::pair<std::string, std::string> stringPair;
typedef std::pair<int, std::string> intStringPair;

std::map<intStringPair, std::vector<int> > lineNumbers;
std::vector<std::string> input;
std::map<intStringPair, std::vector<stringPair> > marks;

bool isDigit(char c) {
  return '0' <= c && c <= '9';
}
bool isLetter(char c) {
  return ('a' <= c && c <='z') || ('A' <= c && c <= 'Z');
}
bool isAlpha(char c) {
  return isDigit(c) || isLetter(c);
}

std::string toBig(std::string x){
  for(int i = 0; i < (int)x.size(); i++){
    if (isLetter(x[i]))
      x[i] = toupper(x[i]); //?
  }
  return x;
}

bool correctMark(std::string &x){
  return 							(
      x == "NZAL" 		||
      x == "ZAL"  		||
      x == "2" 				||
      x == "3" 				||	
      x == "3,5"			||
      x == "4"				||
      x == "4,5"			||
      x == "5"				||
      x == "5!"       ||
      x == 						"");
}

bool correctNumber(std::string &x){
  if((int)x.size() != 5) return false;
  for(int i = 0; i < (int)x.size(); i++)
    if (!isDigit(x[i]))
      return false;
  return true;
}

void parseError(int ln) {
  std::cerr << "Parse error" << std::endl << "Line " << ln+1 << ": " << input[ln] << '\n';
}
int toInt(std::string s) {
  int x =0;
  for(int i = 0; i < (int)s.size(); i++) {
    x *= 10;
    x += s[i] - '0';
  }
  return x;

}
void readLine(int lineNumber) {
  //std::cerr << "readline\n";
  if (input[lineNumber].size() == 0) {
    parseError(lineNumber);
    return;
  }
  //std::cerr << "non empty\n";
  std::istringstream ls(input[lineNumber]);
  std::string code, index, mk1 = "", mk2 = "", a, b;

  try {
//    std::cerr << "trying\n";
    ls >> a >> b;
    if (isLetter(a[0])){ //kod przedmiotu
//      std::cerr << "subject first\n";
      code = a;
      index = b;
    } else if (isDigit(a[0])){ //nr indeksu
//      std::cerr << "index first\n";
      index = a;
      code = b;
    } else { //error
//      std::cerr << "error\n";
      parseError(lineNumber);
      return;
    }	
    if (!isDigit(index[0]) || !isLetter(code[0])){
      parseError(lineNumber);
      return;
    }
    ls >> mk1;
    if (!ls.eof())
      ls >> mk2;
    if (!ls.eof()){ //nadmiarowe
//      std::cerr << "nadmiarowe\n";
      parseError(lineNumber);
      return;
    }
  } catch(...){
//    std::cerr << "catched exception\n";
    parseError(lineNumber);
    return;
  }
  //std::cerr << "parsing ok\n";

  if (!correctNumber(index) || !correctMark(mk1) || !correctMark(mk2) || mk1 == ""){

    parseError(lineNumber);
    return;
  }
  code = toBig(code);
  intStringPair key = make_pair(toInt(index), code);

  if (lineNumbers.find(key) == lineNumbers.end())
    lineNumbers[key] = std::vector<int>();
  lineNumbers[key].push_back(lineNumber);

  if(marks.find(key) == marks.end())
    marks[key] = std::vector<stringPair>();
  marks[key].push_back(make_pair(mk1,mk2));

}

void processEntry(std::pair<intStringPair, std::vector<stringPair> > entry) {
  stringPair mk = entry.second[0];
  for(int i = 1; i < (int)entry.second.size(); i++) 
    if(entry.second[i] != mk) {
      std::cerr << "Duplicated records" << std::endl;
      for(int i = 0; i < (int)lineNumbers[entry.first].size(); i++)
        std::cerr << "Line " << lineNumbers[entry.first][i] + 1 << ": " << input[lineNumbers[entry.first][i]] << std::endl;
      return;
    }

  if (mk.second != "")
    std::cout << std::setfill('0') << std::setw(5) <<  entry.first.first << " " <<entry.first.second << " " << mk.first << " " << mk.second << std::endl; //nadmiarowe spacje w przypadku 1 oceny
  else
    std::cout << std::setfill('0') << std::setw(5) << entry.first.first << " " << entry.first.second << " " << mk.first << std::endl;
}

void processAll(){
  for_each(marks.begin(), marks.end(), processEntry);
}

int main() {
  std::string line;
  int lineNumber = 0;
  while(!std::cin.eof()) {
    getline(std::cin, line);
    input.push_back(line);
    if (line.size() == 0 && std::cin.eof()) break;
    readLine(lineNumber++);
  }
  processAll();
}

